﻿
namespace CrudCategories.Web
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data.Linq;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using Microsoft.ServiceModel.DomainServices.LinqToSql;


    // Implements application logic using the EarthDataContext context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    // [RequiresAuthentication]
    [EnableClientAccess()]
    public class DomainServiceEarth : LinqToSqlDomainService<EarthDataContext>
    {

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        public IQueryable<Country> GetCountries()
        {
            return this.DataContext.Countries;
        }

        public void InsertCountry(Country country)
        {
            this.DataContext.Countries.InsertOnSubmit(country);
        }

        public void UpdateCountry(Country currentCountry)
        {
            this.DataContext.Countries.Attach(currentCountry, this.ChangeSet.GetOriginal(currentCountry));
        }

        public void DeleteCountry(Country country)
        {
            this.DataContext.Countries.Attach(country);
            this.DataContext.Countries.DeleteOnSubmit(country);
        }

        // TODO:
        // Consider constraining the results of your query method.  If you need additional input you can
        // add parameters to this method or create additional query methods with different names.
        public IQueryable<Town> GetTowns()
        {
            return this.DataContext.Towns;
        }

        public void InsertTown(Town town)
        {
            this.DataContext.Towns.InsertOnSubmit(town);
        }

        public void UpdateTown(Town currentTown)
        {
            this.DataContext.Towns.Attach(currentTown, this.ChangeSet.GetOriginal(currentTown));
        }

        public void DeleteTown(Town town)
        {
            this.DataContext.Towns.Attach(town);
            this.DataContext.Towns.DeleteOnSubmit(town);
        }
    }
}


